package com.itheima.controller.backend.security;

import com.itheima.Service.Impl.CheckItemService;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckItem;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkitem")
@Slf4j
public class CheckItemController {

    @Autowired
    private CheckItemService checkItemService;

    @PostMapping("/add")
    public Result add(@RequestBody CheckItem checkItem){
        log.info("新增检查项");
        checkItemService.add(checkItem);

        return new Result(true,"新增检查项成功",null);
    }

    @PostMapping("/findPage")
    public PageResult page(@RequestBody QueryPageBean queryPageBean){
        log.info("分页查找");
        PageResult pageResult = checkItemService.pageQuery(queryPageBean);

        return pageResult;
    }

    @PostMapping("/edit")
    public Result update(@RequestBody CheckItem checkItem){
        log.info("修改检查项");
        checkItemService.update(checkItem);
        return new Result(true,"检查项修改成功",null);
    }

    @GetMapping("/findById/{idName}")
    public Result searchByIdorName(@PathVariable Long idName){
        log.info("条件查询");
        List<CheckItem> itemList = checkItemService.searchByIdorName(idName);

        return new Result(true,"查找成功", itemList);
    }
}
